/* 
@创建Id
*/
const createId = () => {
    let arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    let id = ""
    arr.forEach(ele => {
        let index = Math.floor(Math.random() * 10)
        id += index
    })
    return id
}

/* 
@创建token
*/
const jwt = require('jsonwebtoken')
const { resolve } = require('path')
const createToken = (req) => {
    const payload = req.body
    const secretKey = 'chouqin'
    const token = jwt.sign(payload, secretKey, { expiresIn: '1h' }); //1小时过期
    return token
}

/* 
@验证token
*/
const verifyToken = (token) => {
    return new Promise((resolve, reject) => {
        const secretKey = 'chouqin'
        jwt.verify(token, secretKey, (err, decode) => {
            if (err) {
                resolve(0)
            }
            else {
                resolve(1)
            }
        })
    })
}



/* 
@需要校验的接口
*/
const verifyArr=[]

module.exports = {
    createId,
    createToken,
    verifyToken,
    verifyArr
}